home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / COMMUNIC / BULLETIN / 0340A.ZIP / OCOM_SRC.ARC / COM_SRC.C < prev    next >
C/C++ Source or Header  |  1986-12-28  |  4KB  |  165 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*               The Opus Computer-Based Conversation System                */
  3. /*       (c) Copyright 1986, Wynn Wagner III, All Rights Reserved           */
  4. /*--------------------------------------------------------------------------*/
  5.  
  6.  
  7. /*--------------------------------------------------------------------------*/
  8. /* NOTE: The following is a sample only.  It is intended to point you in    */
  9. /*       a general direction.  It is probably not usable code As Is.        */
  10. /*--------------------------------------------------------------------------*/
  11.  
  12.  
  13. #include <stdio.h>
  14. #include "com.h"
  15.  
  16. #define begin    {
  17. #define end      }
  18.  
  19.  
  20.  
  21. #define SENDBYTE(c)  {while(!(_Com_(0x0b,c)));}
  22.  
  23. extern int timer(int);    /* <- you have to write it (int==10ths of a sec.) */
  24. extern int TIMED_READ(int); /* <- your routine,too. Return char;INT is sec. */
  25.  
  26. int max_baud = 2400;
  27. int com_port = COM1;
  28.  
  29.  
  30. /*--------------------------------------------------------------------------*/
  31. /* OCOM_BAUD                                                                */
  32. /*--------------------------------------------------------------------------*/
  33. void ocom_baud(baud)
  34.    int baud;
  35.    begin
  36.       register int i;
  37.  
  38.          switch( baud )
  39.          begin
  40.             case  300   : i = BAUD_300;   break;
  41.             case 1200   : i = BAUD_1200;  break;
  42.             case 2400   : i = BAUD_2400;  break;
  43.             case 4800   : i = BAUD_4800;  break;
  44.             case 9600   : i = BAUD_9600;  break;
  45.             case 19200  : i = BAUD_19200; break;
  46.             default     : fprintf(stderr,"Bizarre baud rate");
  47.                           exit(1);
  48.          end /* switch */
  49.  
  50.       MDM_ENABLE(i);
  51.  
  52.    end /* ocom_baud */
  53.    
  54.  
  55.  
  56. /*--------------------------------------------------------------------------*/
  57. /* OCOM_INSTALL                                                             */
  58. /*--------------------------------------------------------------------------*/
  59. void ocom_install()
  60.    begin
  61.  
  62.       if (MDM_INSTALL(com_port)!=0x1954)
  63.            begin
  64.               fprintf(stderr,"\nOpus!comm isn't responding.\n");
  65.               exit(1);
  66.          end
  67.  
  68.       ocom_baud(max_baud);
  69.  
  70.    end /* ocom_install */
  71.  
  72.  
  73.  
  74. /*--------------------------------------------------------------------------*/
  75. /* SEND CMD (no echo to console)                                            */
  76. /*--------------------------------------------------------------------------*/
  77. void mdm_sendcmd( value )
  78.    char *value;
  79.    begin
  80.       register int i;
  81.  
  82.       XON_DISABLE();
  83.  
  84.       for (i=0; value[i]; i++)
  85.          if (value[i]=='|')     /* signal to send a carraige return */
  86.             begin
  87.                SENDBYTE('\r');
  88.                timer(5);
  89.             end
  90.          else if (value[i]=='~') timer(18); /* pause for a half second */
  91.          else
  92.             begin
  93.                SENDBYTE(value[i]);
  94.                timer(1);
  95.             end
  96.  
  97.       timer(1);
  98.       XON_ENABLE();
  99.  
  100.    end /* send command to modem */
  101.  
  102.  
  103. /*--------------------------------------------------------------------------*/
  104. /* OCOM_INIT                                                                */
  105. /*--------------------------------------------------------------------------*/
  106. void ocom_init()
  107.    begin
  108.       register int tries;
  109.  
  110.  
  111.       for(tries=0; tries<5; tries++)
  112.          begin
  113.  
  114.             CLEAR_OUTBOUND();
  115.             DTR_ON();
  116.             timer(1);
  117.  
  118.             ocom_baud(max_baud);
  119.  
  120.             CLEAR_INBOUND();
  121.             CLEAR_OUTBOUND();
  122.  
  123.             XON_ENABLE();
  124.  
  125.             mdm_sendcmd("|ATQ0E0H0M0V1S0=1X6|"); /* send USR2400 init */
  126.  
  127.             c = TIMED_READ(5);   /* give modem 5 seconds to respond */
  128.             if (c==0x0d) return; /* if modem responds with <cr>, it's OK! */
  129.  
  130.             fprintf(stderr,"Trouble setting up modem");
  131.             DTR_OFF();
  132.             MDM_DISABLE();
  133.             if (MDM_INSTALL(ctl.com_port)!=0x1954)
  134.                begin
  135.                   fprintf(stderr,"\nOpus!comm isn't responding.\n");
  136.                   exit(2);
  137.                end
  138.          end
  139.  
  140.       exit(2);
  141.        
  142.    end /* ocom_init */
  143.  
  144.  
  145. void main()
  146.    begin
  147.  
  148.        ocom_install();
  149.       ocom_init();
  150.  
  151.       /*
  152.       .
  153.       .
  154.       .
  155.       .
  156.       .
  157.       */
  158.  
  159.       MDM_DISABLE();
  160.    end
  161.  
  162.  
  163. /* END OF FILE: com_src.c */
  164.  
  165.